package com.example.myapplication.model;


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author: rongfeng
 * @date: 2020/9/2
 * @description
 */
public class MyAnnotaionTest {
    public static void main(String[] args) {
        A a = new A();
        Class c = A.class;
        Method[] methods = c.getDeclaredMethods();
        for (Method method : methods) {
            MyAnnotation annotation = method.getAnnotation(MyAnnotation.class);
            if (annotation != null) {
                try {
                    String string = annotation.value1();
                    System.out.println(string);
                    if (string.equals("aaa")) {
                        method.invoke(a);
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public static class A {
        @MyAnnotation(value1 = "aaa")
        public void test() {
            System.out.println("哈哈哈");
        }
    }


}
